<?php
if (!(defined('IN_IA'))) 
{
	exit('Access Denied');
}
class Index_Page extends WebPage
{

/******************************文章咨询首页*************************/
	public function bannerlist(){
		
       global $_W,$_GPC;
        $uniacid=$_W['uniacid'];
        $title=$_GPC['banner_title'];
        $where='';
        if($title!=''){
            $where = "and banner_title like'%".$title."%'" ;
        }        
        $pindex = max(1, intval($_GPC['page']));
        $psize = 8;
        $sql="select * from ".tablename('bd_banner')." where `uniacid`='$uniacid' $where order by banner_sort desc LIMIT " . ($pindex - 1) * $psize . ",{$psize}";
        $list=pdo_fetchall($sql);
        $total = pdo_fetchcolumn("select * from ".tablename('bd_banner')." where `uniacid`='$uniacid' $where");
        $pager = pagination($total, $pindex, $psize);
        $i = ($pindex - 1) * $psize+1;

        include $this->template();
	}

    /****************批量删除********************************/
	public function banner_editall(){
		global $_W,$_GPC;
		$uniacid=$_W['uniacid'];
		if(empty($_GPC['xuanze'])){
            $this->error('未选择数据','',0);
        }
		if($_GPC['piliang'] == 1){
                    //批量删除
			foreach ($_GPC['xuanze'] as $key => $value) {
				$data['banner_id']=$value;
                $data['uniacid'] = $uniacid;
                pdo_delete('bd_banner',$data);
             }
             $this->success('删除成功','',2);
		}
	}

	/****************添加文章********************************/
    public function banner_add() {
        global $_W,$_GPC;
        $uniacid=$_W['uniacid'];
        $uid=$_W['uid'];
        load()->func('tpl');
        
        $jixu=$_GPC['jixu'];
        if($_W['ispost']){
            $data=array();
            $data['banner_thumb']=$_GPC['banner_thumb'];
            $data['banner_title']=$_GPC['banner_title'];
            $data['is_show']=$_GPC['is_show'];
            $data['banner_sort']=$_GPC['banner_sort'];
            $data['banner_url']=$_POST['banner_url'];
            $data['banner_url_type']=$_POST['banner_url_type'];
            $data['uniacid']=$uniacid;
            $data['uid']=$uid;
            $data['add_time']=date("Y-m-d H:i:s");
            $data['last_time']=date("Y-m-d H:i:s");
            $res=pdo_insert('bd_banner',$data); 
            if(!empty($jixu)){
            	$this->success('添加成功','',2);
            }else{
            	$this->success('添加成功','banner/index/bannerlist');
            }
        }
        include $this->template();
	}
    /*
    * 修改资讯
     */
    public function banner_edit(){
        global $_W,$_GPC;
        load()->func('tpl');
        $id=$_GPC['banner_id'];
        $uniacid=$_W['uniacid'];
        $banner=pdo_get('bd_banner',array('banner_id'=>$id,'uniacid'=>$uniacid));

        if($_POST['banner_id']){
            $data=array();
            $id=$_POST['banner_id'];
            $data['banner_thumb']=$_POST['banner_thumb'];
            $data['banner_title']=$_POST['banner_title'];
            $data['banner_sort']=$_POST['banner_sort'];
            $data['is_show']=$_POST['is_show'];
            $data['banner_url']=$_POST['banner_url'];
            $data['banner_url_type']=$_POST['banner_url_type'];
            $data['last_time']=date("Y-m-d H:i:s");
            $res=pdo_update('bd_banner',$data,array('banner_id'=>$id));
            $this->success('修改成功','banner/index/bannerlist');
        }
        include $this->template();

    }

    /*
    * 删除资讯
     */
    public function banner_del(){
        global $_W,$_GPC;
        $uniacid=$_W['uniacid'];
        if($_GPC['banner_id']){
            $id=$_GPC['banner_id'];
            $data=pdo_delete('bd_banner',array('banner_id'=>$id,'uniacid'=>$uniacid));
            $this->success('删除成功','banner/index/bannerlist');
        }
    }
    /*
     * 去除富文本内的字体
     * 2018年1月19日13:22:00
     */
    public function fwb_del_font($str){
        $str = htmlspecialchars_decode($str);
        $re = preg_replace("/font-family:.*;/i",'',$str);
        $re = preg_replace("/font-family:.*\"/i",'"',$re);
        return $re;
    }

}

?>